﻿@using FTBS.Models.Entities;
@model List<FTBS.Models.Entities.Promotion>
@{     
    ViewBag.Title = "Khuyến mãi";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<Schedule> listSchedules = ViewBag.ListSchedule;
    string minutes = "";
    string hours = "";
    var currentHour = DateTime.Now.Hour;
    var currentDay = DateTime.Now;
}
<style>
    .description {
        display: -webkit-box;
        max-width: 100%;
        margin: 0 auto;
        font-size: 12px;
        -webkit-line-clamp: 8;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .filmkind {
        padding: 5px;
        font-size: 27px;
        background-color: rgb(83, 141, 160);
        color: white;
    }

    .filminfo {
        width: 100%;
        padding-left: 20px;
        border-bottom: #ddd 1px solid;
        padding-bottom: 5px;
        border-top: solid 1px #fff;
    }

    .filmpart {
        display: inline-block;
        vertical-align: top;
    }

    .filmtitle {
        font-size: 21px;
        color: red;
    }

    .showtime {
        background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#E46B54), to(#251613));
        width: 49px;
        text-align: center;
        border-radius: 3px;
        margin: 2px;
        display: inline-block;
    }
</style>
<div class="panel" style="background-color: white; margin-top: 20px; margin-left: 15px; width: 97.5%; min-height: 485px">
    @if (Model.Count() > 0 )
    {        
        <div>
            <div class="filmkind">Khuyến mãi</div>
            @foreach (var item in Model)
            {
                <div class="filminfo">
                    <div class="filmpart" style="width: 20%">
                        <div class="filmtitle">
                            @item.PromotionName
                            <div style="border: 1px solid black">
                                <a>
                                    <img src="~/Image/Promotion/@item.ImageURL" style="height: 230px; width: 100%"/>
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="filmpart" style="width: 40%; margin: 0px 30px 0px 10px;">
                        <div style="margin-top: 30px; border-radius: 5px;">
                            <table class="table bordered hovered">
                                <tr>
                                    <td style="width: 100px; font-weight: bold">Từ ngày:</td>
                                    <td>@item.FromDate.ToString("dd/MM/yyyy")</td>
                                </tr>
                                <tr>
                                    <td style="font-weight: bold">Đến ngày:</td>
                                    <td>@item.ToDate.ToString("dd/MM/yyyy")</td>
                                </tr>
                                <tr>
                                    <td style="font-weight: bold">Giảm giá:</td>
                                    <td>@item.Rate %</td>
                                </tr>
                            </table>
                        </div>
                        <div style="margin-top: 27px; height: 20%;">
                            <p class="description" style="line-height: 13pt">@item.Description</p>
                        </div>
                    </div>
                    <div class="filmpart" style="width: 30%; overflow-y: auto; height: 280px; padding: 0px 0px 0px 20px; margin: 10px 0px 10px 0px; border: solid 1px #ddd; background-color: rgba(223, 215, 37, 0.36)">
                        @{ 
                var listOnTheater = listSchedules.Where(s => s.PromotionId == item.PromotionId).Select(s => s.Theater.TheaterName).Distinct();
                foreach (var theater in listOnTheater)
                {
                            <strong style="margin-top: 5px">@theater</strong>
                    var listOnFilm = listSchedules.Where(s => s.PromotionId == item.PromotionId && s.Theater.TheaterName == theater).Select(s => s.Film.Name).Distinct();
                    foreach (var film in listOnFilm)
                    {
                            <div style="padding-left: 15px"><a>@film</a></div>
                        var listOnDate = listSchedules.Where(s => s.PromotionId == item.PromotionId && s.Theater.TheaterName == theater && s.Film.Name == film).Select(s => s.Date).Distinct();
                        foreach (var date in listOnDate)
                        {
                            <div style="font-size: 15px; padding: 5px 0px 5px 25px">@date.ToString("dd/MM/yyyy")</div>
                            var listOnTime = listSchedules.Where(s => s.PromotionId == item.PromotionId && s.Theater.TheaterName == theater && s.Film.Name == film && s.Date == date);
                            foreach (var time in listOnTime)
                            {
                                var showtimeHour = time.ShowTime.Time.Hours;
                                var showtimeDay = time.Date;
                                if (time.ShowTime.Time.Minutes < 10)
                                {
                                    minutes = "0" + time.ShowTime.Time.Minutes.ToString();
                                }
                                else if (time.ShowTime.Time.Minutes >= 10)
                                {
                                    minutes = time.ShowTime.Time.Minutes.ToString();
                                }

                                if (time.ShowTime.Time.Hours < 10)
                                {
                                    hours = "0" + time.ShowTime.Time.Hours.ToString();
                                }
                                else if (time.ShowTime.Time.Hours >= 10)
                                {
                                    hours = time.ShowTime.Time.Hours.ToString();
                                }
                                if (showtimeDay == currentDay)
                                {
                                    if (showtimeHour >= currentHour + (time.Theater.DeadlineForBooking / 60))
                                    {
                            <div class="showtime" style="padding-left: 35px">@Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket", "Schedule", new { @showtimeId = time.ShowTime.ShowTimeId, @filmId = time.FilmId, @theaterId = time.TheaterId, @roomId = time.RoomId, @scheduleId = time.ScheduleId }, new { style = "color:white" }) </div>
                                    }
                                    if (showtimeHour < currentHour + (time.Theater.DeadlineForBooking / 60))
                                    {
                            <button class="button small" style="color: black; margin-left: 40px;padding-left: 35px" disabled>@hours:@minutes</button>
                                    }
                                }
                                else if (showtimeDay > currentDay)
                                {
                            <div class="showtime" style="margin-left: 35px">@Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket", "Schedule", new { @showtimeId = time.ShowTime.ShowTimeId, @filmId = time.FilmId, @theaterId = time.TheaterId, @roomId = time.RoomId, @scheduleId = time.ScheduleId }, new { style = "color:white" })</div>
                                }
                                else
                                { }

                            }
                        }
                    }
                            <div style="border-top: solid 1px #ddd; margin-top: 10px; border-bottom: 1px solid #fff"></div>
                }
                        }

                    </div>
                </div>                 
            }
        </div>
    }
    else
    {
        <div class="panel" style="background-color: white; margin-top: 20px; margin-left: 15px; width: 97.5%; height: 485px">
            <div class="filmkind">Khuyến mãi</div>
        </div>
    }
</div>
